<!--
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-05-06 23:09:53
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-05-10 10:39:30
 * @FilePath: /data-center-web-update/src/components/Pagination/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <el-scrollbar>
        <div :class="{ hidden: hidden }" class="pagination">
            <el-pagination
                v-model:current-page="currentPage"
                v-model:page-size="pageSize"
                :background="background"
                :layout="layout"
                :page-sizes="pageSizes"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
            />
        </div>
    </el-scrollbar>
</template>

<script setup lang="ts">
const props = defineProps({
    total: {
        required: true,
        type: Number as PropType<number>,
        default: 0
    },
    page: {
        type: Number,
        default: 1
    },
    limit: {
        type: Number,
        default: 20
    },
    pageSizes: {
        type: Array as PropType<number[]>,
        default() {
            return [10, 20, 30, 50];
        }
    },
    // TODO: jumper会导致 label is about to be deprecated in version 2.8.0, please use aria-label instead. 原因是element-plus内部组件错误，坐等修复
    layout: {
        type: String,
        default: 'total, sizes, prev, pager, next, jumper'
    },
    background: {
        type: Boolean,
        default: true
    },
    autoScroll: {
        type: Boolean,
        default: true
    },
    hidden: {
        type: Boolean,
        default: false
    }
});

const emit = defineEmits(['pagination', 'update:page', 'update:limit']);

const currentPage = useVModel(props, 'page', emit);

const pageSize = useVModel(props, 'limit', emit);

function handleSizeChange(val: number) {
    emit('pagination', { page: currentPage, limit: val });
}

function handleCurrentChange(val: number) {
    currentPage.value = val;
    emit('pagination', { page: val, limit: props.limit });
}
</script>

<style lang="scss" scoped>
.pagination {
    padding: 12px;

    &.hidden {
        display: none;
    }
}
</style>
